<html lang="en"><head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Connect Web Server</title>


    <!-- Framework CSS -->
    
    <link rel="stylesheet" href="css/blueprint/screen.css" type="text/css" media="screen, projection">
    <link rel="stylesheet" href="css/blueprint/print.css" type="text/css" media="print">
    <!--[if lt IE 8]><link rel="stylesheet" href="css/blueprint/ie.css" type="text/css" media="screen, projection"><![endif]-->

    <!-- Import fancy-type plugin for the sample page. -->
    <link rel="stylesheet" href="css/blueprint/fancytype.css" type="text/css" media="screen, projection">
    
    <!-- Custom styles to override framework -->
     <link rel="stylesheet" href="css/main.css" type="text/css" media="screen, projection">
  </head>
<body>
    <div class="container">
   
    
     <br/>
      <h1><a href="/"><img src="images/ConnectLogo.png"  alt="Connect" style="vertical-align:middle;" ></a>  Connect Web Server Reference</h1>
      
      <hr>
      <h2 class="alt"><a href="/">Home</a> | <a href="scriptingRef.html">Scripting</a> | Freemarker Extensions | <a href="serverConfigGuide.html">Server Configuration</a></h2>
    
      <hr>
      <hr class="space">
      <div class="span-20 prepend-1">
       <h3>Basics</h3>
       <p> Connect uses the Freemarker templating engine to produce server side populated templated pages. In the initialisation of the Freemarker engine, we make avaliable a number of internal objects: </p>
          <ul>
              <li>request - a <b>WrappedRequest</b> object exposing the HTTP request</li>
              <li>response - a <b>WrappedResponse</b> object exposing the HTTP response</li>
              <li>session - a <b>WrappedSession</b> object exposing the user session</li>
              
              <li>server - a <b>HashMap</b> object exposing server name, login URL and datetime</li>
              <li>data - a <b>DataManager</b> object exposing the datasources configured on the server</li>
          </ul>
          
          
		<hr>
        <h3>Usuage</h3>
       <p> Below are examples of using the above objects in your pages </p>
          
          <h5>Response headers, encoding and content type.</h5>
		<pre class="code">

${response.setContentType("text/html")}
${response.setHeader("Cache-Control", "no-cache")}
${response.setCharacterEncoding("UTF-8")}
<#--${response.setContentType("text/plain")}-->
</pre>
       <h5>Server Info and login box</h5>

<pre class="code">
&lt;div class=&quot;right box&quot;&gt; ${server.time.getTimeString()} ${server.time.getDateString()}
   &lt;#if !session.isAnonymous()&gt;
        &lt;br/&gt; User: ${session.getUser()} [&lt;a href=&quot;doLogout&quot;&gt;Logout&lt;/a&gt;]
   &lt;#else&gt;
   &lt;form action=&quot;/doLogin&quot; method=&quot;GET&quot; &gt;
        Username:&lt;input name=&quot;name&quot; type=&quot;text&quot; /&gt;&lt;BR/&gt;
        Password:&lt;input name=&quot;password&quot; type=&quot;password&quot;/&gt;
        &lt;button name=&quot;Submit&quot; type=&quot;submit&quot;&gt;Login&lt;/button&gt; 
    &lt;/form&gt;
   &lt;/#if&gt;
 &lt;/div&gt;
</pre>
        


<h5>Populating controls from datasources</h5>
<pre class="code">
  Region:&lt;select id=&quot;region&quot;&gt;
        	&lt;option&gt;- Please Select -&lt;/option&gt;
                &lt;#assign dsRegion = data.getDataSource(&quot;JDBCRegionDataSource&quot;)&gt;
	           &lt;#list dsRegion.doQuery() as record&gt;
	               &lt;option&gt;${record.get(&quot;Region&quot;)}&lt;/option&gt; 
		  &lt;/#list&gt;
          &lt;/select&gt;
</pre>
          

<h5>Passing request parameters to datasources</h5>
<pre class="code">
   &lt;#assign ds = data.getDataSource(&quot;JDBCDataSource&quot;)&gt;
       &lt;#assign region = request.getParameter(&quot;region&quot;)!&quot;&quot;&gt;
       &lt;#if region != &quot;&quot;&gt; 
       		&lt;#assign ds = ds.setParam(&quot;region&quot;,region) &gt;
       &lt;/#if&gt;
        
</pre>

<p>
    To see these in action, try out the examples that come with the base install. You will need to configure up the external sources for the JDBC examples - the SQL to populate the databases is in the www/data folder.
</p>

          <h3>Viewing source</h3>
          <p> To view the source code of your page, simply append <b>?viewSource</b> to the page URL.</p>
        
        
      </div>
      <hr/>
      <div class="last quiet right"> 
          <a href="http://www.binarycube.com"><img src="images/logo-bw.png" width="150" /></a><br/>
      </div>
</div>
  

</body></html>